#!/usr/bin/env python3
"""
MCP服务器 - 提供HTTP接口的主服务
"""

import logging
from fastmcp import FastMCP
from config import Config
from tools.bing_search import BingSearchTool
from tools.gl_search import gl_forum_search as gl_search_func
# 配置日志
logging.basicConfig(level=getattr(logging, Config.LOG_LEVEL))
logger = logging.getLogger(__name__)

# 创建主MCP服务器实例
mcp = FastMCP("GanLa MCP Server")

bing_search_tool = BingSearchTool()
# gl_search_tool = GLSearchTool()
    
# 注册工具到MCP实例
@mcp.tool()
async def bing_search(query: str, count: int = 5) -> str:
    """Bing网络搜索"""
    return await bing_search_tool.bing_search(query, count)

@mcp.tool()
async def gl_forum_search(topic: str) -> str:
    """GL论坛搜索"""
    return await gl_search_func(topic)

@mcp.tool()
async def health_check() -> str:
    """健康检查"""
    return "✅ GanLa MCP服务器运行正常"

if __name__ == "__main__":
    logger.info("启动 GanLa MCP 服务器...")
    logger.info(f"服务器地址: http://{Config.SERVER_HOST}:{Config.SERVER_PORT}")
    logger.info(f"模拟模式: {Config.MOCK_MODE}")
    
    # 使用FastMCP内置的run方法启动服务器
    mcp.run(
        transport="http",
        host=Config.SERVER_HOST,
        port=Config.SERVER_PORT
    )